package com.mengye.socket.controller;

import com.mengye.socket.entity.SocketMessage;
import com.mengye.socket.parkourWebSocket.WebSocketUsersParkour;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/message")
public class MessageController {

    @PostMapping("/postMessageParkour")
    public void postMessage(@RequestBody SocketMessage socketMessage) {
        log.info("收到消息:{}",socketMessage);
        if (ObjectUtils.isEmpty(socketMessage)){
            return;
        }
        if (StringUtils.isEmpty(socketMessage.getName())){
            return;
        }
        if (StringUtils.isEmpty(socketMessage.getData())){
            return;
        }
        WebSocketUsersParkour.sendMessageToUsersByText(socketMessage.getData());
    }

}
